package com.example.miniappssm.service.serviceImpl;

import com.example.miniappssm.bean.Cart;
import com.example.miniappssm.bean.Goods;
import com.example.miniappssm.mapper.CartMapper;
import com.example.miniappssm.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {

    @Autowired
    CartMapper cartMapper;

    @Override
    public List<Goods> showAllGoodsFromUserIdInCart(Integer userId) {
        return cartMapper.selectAllGoodsFromUserIdInCart(userId);
    }

    @Override
    public void addGoodsInCart(Cart cart) {
        //防止用户重复添加
        if (cartMapper.checkIsSameInOneUserId(cart) == null) {
            cartMapper.insertGoodsInCart(cart);
        }
    }

    @Override
    public void removeGoodsFromCartByCartId(Integer cartId) {
        cartMapper.deleteGoodsFromCartByCartId(cartId);
    }
}
